package com.daoeping.action;

import java.util.ArrayList;
import java.util.List;
import com.daoeping.domain.JsonData;
import com.daoeping.service.CityService;
import com.daoeping.util.ConverntJsonData;
import com.opensymphony.xwork2.ActionSupport;

public class CityAction extends ActionSupport{
	
	private static final long serialVersionUID = 5085044089395250829L;
	private CityService bsc_cityService;
	private JsonData jsonData;
	private List<Object[]> bsc_cityList;
	
	public CityService getBsc_cityService() {
		return bsc_cityService;
	}

	public void setBsc_cityService(CityService bsc_cityService) {
		this.bsc_cityService = bsc_cityService;
	}

	public List<Object[]> getBsc_cityList() {
		return bsc_cityList;
	}

	public void setBsc_cityList(List<Object[]> bsc_cityList) {
		this.bsc_cityList = bsc_cityList;
	}

	public JsonData getJsonData() {
		return jsonData;
	}

	public void setJsonData(JsonData jsonData) {
		this.jsonData = jsonData;
	}
	
	

	public String findAllCity(){
		jsonData = new JsonData();
		bsc_cityList = bsc_cityService.findBsc_cityList();
		List<List<String>> newlist = new ArrayList<List<String>>();
		List<String> list = new ArrayList<String>();
		for (int i = 0; i < bsc_cityList.size(); i++) {
			Object[] obj = bsc_cityList.get(i);
			if(list.size()==0){
				list.add(obj[0]+","+obj[1]);
			}
			list.add(obj[2]+","+obj[3]);
			if((i<bsc_cityList.size()-1&&!bsc_cityList.get(i)[0].equals(bsc_cityList.get(i+1)[0]))||i == bsc_cityList.size()-1){
				newlist.add(list);
				list = new ArrayList<String>();
			}
		}
		jsonData.setJsonData(new ConverntJsonData().getJsonData(newlist)+"");
		
		return "allcity";
		
	}
	
}
